<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2018/5/31
 * Time: 上午10:32
 */

namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Api\User\Transformers\UserBillTransformer;
use App\Http\Controllers\Controller;
use App\Modules\User\Services\UserBillService;
use Illuminate\Http\Request;

class UserBillController extends Controller
{

    /**
     * @apiVersion 1.0.0
     * @apiDescription 用户流水
     * @api {GET} v1/user/bills 用户流水
     * @apiName getListBill
     * @apiGroup User
     *
     * @apiParam   {String}  [type] 类型 查看接口 [Pay:支付；Withdraw:提现；RewardIn:打赏进钱；RewardOut:打赏出钱；]
     * @apiParam   {String}  [start_time] 开始时间(可不传)
     * @apiParam   {String}  [end_time] 结束时间(可不传)
     *
     * @apiSuccess   {Number}  id 用户ID
     * @apiSuccess   {Number}  amount 提现金额.
     * @apiSuccess   {String}  type 类型.
     * @apiSuccess   {String}  title 标题.
     * @apiSuccess   {String}  remark 备注.
     * @apiSuccess   {Number}  task_id 任务ID.
     * @apiSuccess   {Number}  order_id 充值记录ID.
     * @apiSuccess   {Number}  pay_withdraw_cash_id 提现记录ID.
     * @apiSuccess   {String}  created_time 创建时间.
     * @apiSuccess   {String}  updated_time 更新时间.
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *         "code": 0,
     *         "msg": "",
     *         "data": {
     *                   "list": [
     *                           {
     *                                       "id":1
     *                                       "amount": 330.00,
     *                                       "type": "Pay",
     *                                       "title": "充值",
     *                                       "remark": null,
     *                                       "task_id": 0,
     *                                       "order_id": 0,
     *                                       "pay_withdraw_cash_id": 0,
     *                                       "created_time": "2017-12-01 16:58:55",
     *                                       "updated_time": "2017-12-01 16:58:59"
     *                               }
     *                       ],
     *                   "meta": {
     *                       "total": 2,
     *                       "per_page": 15,
     *                       "current_page": 1,
     *                       "last_page": 1,
     *                       "next_page_url": "",
     *                       "prev_page_url": ""
     *                   }
     *              }
     *     }
     */
    function getListBill(Request $request) {
        if($this->isNotLogin()) {
            return response()->error("NOT_LOGIN");
        }
        $start_time = $this->getParameterStartTime($request);
        $end_time = $this->getParameterEndTime($request);
        $typeIn = $request->has('type') ? $request->input('type') : '';

        $searchParams = [
            'uid'=>$this->getLoginUserId(),
            'start_time' => $start_time,
            'end_time' => $end_time,
            'type' => $typeIn,
        ];

        $result = UserBillService::getList($searchParams);

        return response()->pagination(new UserBillTransformer(),  $result);
    }
}